{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cd819fe3-4166-4eb5-ae05-f508390f4ed8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_breast_cancer\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "x,y=load_breast_cancer().data,load_breast_cancer().target\n",
    "x=StandardScaler().fit_transform(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dead397f-8abc-4853-82b4-007fb71c6968",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最优参数值为：{'coef0': np.float64(0.0), 'gamma': np.float64(0.18329807108324375)}\n",
      "选取该参数值时，模型预测准确率为：0.969591\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import StratifiedShuffleSplit\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "gamma_range=np.logspace(-10,1,20)\n",
    "coef0_range=np.linspace(0,5,10)\n",
    "param_grid=dict(gamma=gamma_range,coef0=coef0_range)\n",
    "cv=StratifiedShuffleSplit(n_splits=5,test_size=0.3,random_state=420)\n",
    "grid=GridSearchCV(SVC(kernel=\"poly\",degree=1),param_grid=param_grid,cv=cv)\n",
    "grid.fit(x,y)\n",
    "print(\"最优参数值为：%s\"%grid.best_params_)\n",
    "print(\"选取该参数值时，模型预测准确率为：%f\"%grid.best_score_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01404383-cc2e-45f2-9e00-4c8806055142",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
